<%-- 
    Document   : list
    Created on : 2014/8/19, 下午 02:19:21
    Author     : Benny
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/javadb?zeroDateTimeBehavior=convertToNull","root","root");
    Statement st=con.createStatement();
    String sql ="select id,username,tel,birthday from person";
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>List</title>
    </head>
    <body>
        <h1>-----List-----</h1>
        <hr>
        <table border="1">
            <tr>
            <td>id</td>
            <td>username</td>
            <td>tel</td>
            <td>birthday</td>
            <td></td>
            </tr>
        
        <%
        ResultSet rs =st.executeQuery(sql);
        while(rs.next()){
            String id =rs.getString("id");
            String username =rs.getString("username");
            String tel =rs.getString("tel");
            String birthday =rs.getString("birthday");
       %>
        <tr>
            <td><%= id %></td>
            <td><%= username %></td>
            <td><%= tel %></td>
            <td><%= birthday %></td>
            <td><a href="update1.jsp?id=<%= id %>">更新</a>
                <input type="button" value="刪除" onclick="doDelete('<%= id %>')">
            </td>
            </tr>
       <%
        }
        rs.close();
        st.close();
        con.close();
        %>
        </table>
        <script>
            function doDelete(x){
                //alert('x:'+x);
                if(confirm('確定要刪除嗎？')){
                    document.getElementById('id').value =x;
                    document.getElementById('form1').submit();
                }
            }
        </script>
        <form action="delete.jsp" id="form1">
            <input type="hidden" name="id" id="id" value="">
        </form>
        <a href="insert1.jsp">繼續新增</a><br>
    </body>
</html>